<template>
    <bi-form ref="form"  label-width="100px">
        <div class="alert alert-warning" style="font-size: 12px; padding: 10px;" >
            用户重新登陆时需要再次更改密码!
        </div>
        
        <bi-form-item label="新密码">
            <bi-input v-model="form.password" required placeholder="请输入初始密码" >
                <template #after>
                    <bi-button @click="randomPassword" >随机</bi-button>
                </template>
            </bi-input>
        </bi-form-item>
    </bi-form>
</template>

<script>
    export default {
        dialog:{
            title:'重置密码',
            width:400,
        },
        data(){
            return {
                form:{
                    password:''
                }
            }
        },
        props:['user_id'],
        methods:{
            randomPassword(){
                this.form.password = Math.random().toString(36).slice(2);
            },
            dialogOk(){
                if(this.$refs.form.check()){
                    this.$ajax({
                        url:this.$url({app:'admin',controller:'user',action:'resetPassword'}),
                        data:{
                            password:this.form.password,
                            user_id:this.user_id
                        },
                        success:()=>{
                            this.$toast({text:'重置成功',type:'success'});
                            this.dialog.close();
                        }
                    })
                }

                return false;
            }
        }
    }
</script>